package com.itheima.dubbo.mysql.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.itheima.commons.model.domain.Subject;
import com.itheima.dubbo.interfaces.SubjectApi;
import com.itheima.dubbo.mysql.mapper.SubjectMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


@Service
public class SubjectApiImpl implements SubjectApi {

    @Autowired
    private SubjectMapper subjectMapper;

    /**
     * 通过卷子id获取该卷子下的所有题目
     * @param qid
     * @return
     */
    @Override
    public List<Subject> querySubjects(Long qid) {
        List<Subject> subjects = subjectMapper.selectList(Wrappers
                .lambdaQuery(Subject.class)
                .eq(Subject::getQid, qid));
        return subjects;
    }

    /**
     * 通过题目id获取该题目信息
     * @param id
     * @return
     */
    @Override
    public Subject querySubjectsById(Long id) {
        Subject subject = subjectMapper.selectOne(Wrappers
                .lambdaQuery(Subject.class).eq(Subject::getId, id));
        return subject;
    }
}
